package request

import (
	"github.com/asaskevich/govalidator"
	"tizhi_front/response"
)

type IdNameLogin struct {
	IdentityId string `json:"identity_id" example:"370211198106134817"`
	Name       string `json:"name" example:"鲜天麒"`
}

func (i *IdNameLogin) Validate() (ok bool) {
	if len(i.IdentityId) != 0 && len(i.Name) != 0 {
		ok = true
	}
	return
}

type SchoolRollIdNameLogin struct {
	SchoolRollId string `json:"school_roll_id" example:"2018120118122213"`
	Name         string `json:"name" example:"鲜天麒"`
}

func (s *SchoolRollIdNameLogin) Validate() (ok bool) {
	if len(s.SchoolRollId) != 0 && len(s.Name) != 0 {
		ok = true
	}
	return
}

type IdLogin struct {
	StudentId string `json:"student_id" example:"2018120118122213"`
	Password  string `json:"password" example:"2018120118122213"`
}

func (i *IdLogin) Validate() (ok bool) {
	if len(i.StudentId) != 0 && len(i.Password) != 0 {
		ok = true
	}
	return
}

type PhoneLogin struct {
	Phone    string `json:"phone" example:"18810566938"`
	Password string `json:"password" example:"2018120118122213"`
}

func (p *PhoneLogin) Validate() (ok bool) {
	if len(p.Phone) != 0 && len(p.Password) != 0 {
		ok = true
	}
	return
}

type UserInfoUpdate struct {
	UserInfo  response.UserInfo  `json:"user_info"`
	TokenInfo response.TokenInfo `json:"token_info"`
}

type UpdatePass struct {
	OriginPass string             `json:"origin_pass" example:"2018120118122213"`
	NewPass    string             `json:"new_pass" example:"2018120118122213"`
	TokenInfo  response.TokenInfo `json:"token_info"`
}

type ResetPassByPhone struct {
	Phone     string `json:"phone" example:"18810566938"`
	ValidCode string `json:"valid_code" example:"664194"`
	Password  string `json:"password" example:"2018120118122213"`
}

func (r *ResetPassByPhone) Validate() (ok bool) {
	if len(r.Phone) == 0 || len(r.ValidCode) != 6 || len(r.Password) == 0 || len(r.Phone) > 255 || len(r.Password) > 255 {
		return
	}
	ok = govalidator.StringMatches(r.Phone, `^((\+86)|(86))?(1(([35][0-9])|[8][0-9]|[7][06789]|[4][579]))\d{8}$`)
	return
}

type ResetPassById struct {
	StudentName string `json:"student_name" example:"鲜天麒"`
	StudentId   string `json:"student_id" example:"2018120118122213"`
	IdNumber    string `json:"id_number" example:"370211198106134817"`
	Password    string `json:"password" example:"2018120118122213"`
}

func (r *ResetPassById) Validate() (ok bool) {
	if !govalidator.StringLength(r.StudentId, "1", "255") {
		return
	}
	if !govalidator.StringLength(r.Password, "1", "255") {
		return
	}
	ok = true
	return
}

type BlindPhone struct {
	Phone     string             `json:"phone" example:"18811795258"`
	ValidCode string             `json:"valid_code" example:"664194"`
	TokenInfo response.TokenInfo `json:"token_info"`
}

type WechatLogin struct {
	Code string `json:"code" example:"1234"`
}

type WechatBind struct {
	Code      string `json:"code" example:"1234"`
	StudentId string `json:"student_id" example:"2018120118122213"`
	Password  string `json:"password" example:"2018120118122213"`
}
